package cn.myjerry.test.JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * 测试PreparedStatement的使用
 * @author Jerry
 *
 */
public class Demo02 {
	// JDBC 驱动名及数据库 URL
    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
    static final String DB_URL = "jdbc:mysql://localhost:3306/testjdbc?useSSL=true&useUnicode=true&characterEncoding=utf8";
    
    // 数据库的用户名与密码，需要根据自己的设置
    static final String USER = "root";
    static final String PASS = "Jerry1912317";
	
	public static void main(String[] args) throws Exception {
		// 加载驱动类
		Class.forName(JDBC_DRIVER);
		// 建立连接
		Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
		
		String sql = "INSERT INTO User (Name,PassWord,RegTime) VALUES (?, ?, ?)";
		PreparedStatement ps = conn.prepareStatement(sql);
//		ps.setString(1, "孙谱");
//		ps.setString(2, "123456");
		ps.setDate(3, new java.sql.Date(System.currentTimeMillis()));
		
		ps.setObject(1, "靳珍珍");
		ps.setObject(2, "123456");
		ps.setObject(3, new java.sql.Date(System.currentTimeMillis()));
		
		//ps.execute();
		int count = ps.executeUpdate();
		System.out.println(count);
		
	}
}
